﻿using Easy.Cloud.Communication.Sms.Ali;
using Easy.Cloud.Communication.Sms.Core;
using Easy.Cloud.Communication.Sms.Core.Enums;
using Easy.Cloud.Communication.Sms.Submail;
using Easy.Cloud.Communication.Sms.Tencent;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;

namespace Easy.Cloud.Communication.Sms.Client.Provider
{
    public class SmsClientProvider : ISmsClientProviderFactory
    {
        private readonly IServiceProvider _serviceProvider;
        public SmsClientProvider(IServiceProvider serviceProvider = null)
        {
            _serviceProvider = serviceProvider;
        }

        public ISmsClient CreateSmsClient(SmsClientProviderType provider)
        {
            switch (provider)
            {
                case SmsClientProviderType.Tencent:
                    return _serviceProvider.GetRequiredService<TencentSmsClient>();
                case SmsClientProviderType.Ali:
                    return _serviceProvider.GetRequiredService<AliSmsClient>();
                case SmsClientProviderType.Submail:
                    return _serviceProvider.GetRequiredService<SubmailSmsClient>();
                default:
                    throw new ArgumentOutOfRangeException(nameof(provider), provider, null);
            }
        }
    }
}
